﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gao.Poker.Domain;

namespace Gao.Poker.Services
{
    public class MemberRecordService : BaseService
    {
        private static MemberRecordService _instance;

        public static MemberRecordService Instance()
        {
            return _instance ?? (_instance = new MemberRecordService());
        }

        private MemberRecordService()
        {
            
        }

        public void Save(MemberRecord memberRecord)
        {
            if (memberRecord == null) return;

            if (memberRecord.ID == 0)
            {
                DbContext.RechargeLogs.Add(memberRecord);
            }
            else
            {
                var log = DbContext.RechargeLogs.Find(memberRecord.ID);
                DbContext.Entry(log).CurrentValues.SetValues(memberRecord);
            }
            DbContext.SaveChanges();
        }

        public List<MemberRecord> GetMemberRecord(int memberId,DateTime startDate,DateTime endDate)
        {
            return DbContext.RechargeLogs.Where(a => a.MemberID == memberId)
                .Where(a=>startDate < a.CreateDt)
                .Where(a=>endDate > a.CreateDt).ToList();
        }
    }
}
